package com.pig4cloud.pig.mt.manage;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.mt.entity.WxMsgReplyRule;
import com.pig4cloud.pig.mt.service.WxMsgReplyRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 自动回复规则
 */
@RestController
@RequestMapping("/manage/msgReplyRule")
@Api(value = "/manage/wxmsgreplyrule", tags = "自动回复规则管理")
public class MsgReplyRuleManageController {
    @Autowired
    private WxMsgReplyRuleService msgReplyRuleService;

    /**
     * 列表
     */
	@ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/list")
	@PreAuthorize("@pms.hasPermission('mt_wxmsgreplyrule_get')" )
    public R list(@CookieValue String appid, @RequestParam Map<String, Object> params) {
        params.put("appid",appid);
        IPage page = msgReplyRuleService.queryPage(params);

        return R.ok(page);
    }


    /**
     * 信息
     */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/info/{ruleId}")
	@PreAuthorize("@pms.hasPermission('mt_wxmsgreplyrule_get')" )
    public R info(@PathVariable("ruleId") Integer ruleId) {
        WxMsgReplyRule msgReplyRule = msgReplyRuleService.getById(ruleId);

        return R.ok(msgReplyRule);
    }

    /**
     * 保存
     */
	@ApiOperation(value = "新增自动回复规则", notes = "新增自动回复规则")
	@SysLog("新增自动回复规则")
    @PostMapping("/save")
	@PreAuthorize("@pms.hasPermission('mt_wxmsgreplyrule_add')" )
    public R save(@RequestBody WxMsgReplyRule msgReplyRule) {
        msgReplyRuleService.save(msgReplyRule);

        return R.ok();
    }

    /**
     * 修改
     */
	@ApiOperation(value = "修改自动回复规则", notes = "修改自动回复规则")
	@SysLog("修改自动回复规则")
    @PutMapping("/update")
	@PreAuthorize("@pms.hasPermission('mt_wxmsgreplyrule_edit')" )
    public R update(@RequestBody WxMsgReplyRule msgReplyRule) {
        msgReplyRuleService.updateById(msgReplyRule);

        return R.ok();
    }

    /**
     * 删除
     */
	@ApiOperation(value = "通过id删除自动回复规则", notes = "通过id删除自动回复规则")
	@SysLog("通过id删除自动回复规则")
    @DeleteMapping("/delete")
	@PreAuthorize("@pms.hasPermission('mt_wxmsgreplyrule_del')" )
    public R delete(@RequestBody Integer[] ruleIds) {
        msgReplyRuleService.removeByIds(Arrays.asList(ruleIds));

        return R.ok();
    }

}
